﻿Public Class RegexCapturesViewModel
    Inherits RegexViewModelBase
    Implements IEnumerable(Of RegexCaptureViewModel)

#Region "Events"
    ' Insert Event Declarations Here
#End Region

#Region "Properties"
#Region "Constants"
    ' Insert Constant Declarations Here
#End Region

    Private _captures As CaptureCollection
    Public Property Captures() As CaptureCollection
        Get
            Return _captures
        End Get
        Private Set(ByVal value As CaptureCollection)
            _captures = value
        End Set
    End Property

    Private _captureViewModels As IEnumerable(Of RegexCaptureViewModel)
    Public Property CaptureViewModels() As IEnumerable(Of RegexCaptureViewModel)
        Get
            Return _captureViewModels
        End Get
        Private Set(ByVal value As IEnumerable(Of RegexCaptureViewModel))
            _captureViewModels = value
        End Set
    End Property

    Public ReadOnly Property Count As Integer
        Get
            'Subtract 1 because the first item is always the original Match (which is not included in the collection)
            Return Me.CaptureViewModels.Count()
        End Get
    End Property

    Public Overrides ReadOnly Property Index As Integer
        Get
            If Me.Captures.Count > 0 Then
                Return Me.Captures(0).Index
            Else
                Return 0
            End If
        End Get
    End Property

    Public Overrides ReadOnly Property Length As Integer
        Get
            If Me.Captures.Count > 0 Then
                Return Me.Captures(0).Length
            Else
                Return 0
            End If
        End Get
    End Property
#End Region

#Region "Constructors"
    Public Sub New(captures As CaptureCollection, regex As Regex, viewNavigator As IViewNavigator)
        MyBase.New(regex, viewNavigator)

        Me.Captures = captures
        Me.CaptureViewModels =
            From c In Me.Captures.Cast(Of Capture)()
            Where Not TypeOf c Is Match
            Select New RegexCaptureViewModel(c, regex, viewNavigator)
    End Sub
#End Region

#Region "Methods"
    Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of RegexCaptureViewModel) Implements System.Collections.Generic.IEnumerable(Of RegexCaptureViewModel).GetEnumerator
        Return Me.CaptureViewModels.GetEnumerator()
    End Function

    Private Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return GetEnumerator()
    End Function

#Region "Event Raiser Methods"
    ' Insert Method Declarations which Raise an Event Here
#End Region

#Region "Event Handlers"
    ' Insert Method Declarations which Handle an Event Here
#End Region
#End Region

End Class
